<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');

if ( ! function_exists('createqrcoder'))
{

    //qrcoder helper
	if(!extension_loaded('gd')) 
	{
		echo 'you should open the extension=php_gd2.dll in php.ini';
		exit();
	}
    class QRCodeHelper
    {
    	private $value;
    	private $errorCorrectionLevel;
    	private $matrixPointSize;
    	private $matrix;
    	private $filename;

    	public function __construct($value = "http://www.baidu.com",$errorCorrectionLevel = "M",$matrixPointSize = "20",$matrix = '2',$filename = false)
    	{
    		$this->value = $value;
    		$this->errorCorrectionLevel = $errorCorrectionLevel;
    		$this->matrixPointSize = $matrixPointSize;
    		$this->matrix = $matrix;
    		$this->filename = $filename;
    	}

    	public function getPNG()
    	{
    		include_once("phpqrcode.php");
    		return QRcode::png($this->value,$this->filename,$this->errorCorrectionLevel, $this->matrixPointSize,$this->matrix);
    	}

    	public function getValue() {
			return $this->value;
		}
		public function setValue($value) {
			$this->value = $value;
		}
		public function getErrorCorrectionLevel() {
			return $this->errorCorrectionLevel;
		}
		public function setErrorCorrectionLevel($errorCorrectionLevel) {
			$this->errorCorrectionLevel = $errorCorrectionLevel;
		}
		public function getMatrixPointSize() {
			return $this->matrixPointSize;
		}
		public function setMatrixPointSize($matrixPointSize) {
			$this->matrixPointSize = $matrixPointSize;
		}
		public function getMatrix() {
			return $this->matrix;
		}
		public function setMatrix($matrix) {
			$this->matrix = $matrix;
		}
		public function getFilename() {
			return $this->filename;
		}
		public function setFilename($filename) {
			$this->filename = $filename;
		}

    } 
	//$value="http://www.baidu.com";
	//$errorCorrectionLevel = "M";
	//$matrixPointSize = "20";
	//QRcode::png($value, 'filename.png',$errorCorrectionLevel, $matrixPointSize,"2");
	//echo "string";
	//QRcode::png($value, false, $errorCorrectionLevel, $matrixPointSize,"2");
    //echo "aaa";
    //$q = new QRCodeHelper("hello world");
    //$q->setFilename(TMP."img/aaa.png");
    //$q->getPNG();
	function createqrcoder($name,$value)
	{//create one qrcode return the service address
		$q = new QRCodeHelper($value);
	    $q->setFilename(TMP."img/".$name.".png");
	    $q->getPNG();
	    return IMG.$name.".png";
	}
}